

#include "mvr.h"
#include "kvr.h"
#include <iostream>
#include "../hedmodel.h"
#include "../entity/solid.h"
#include "../entity/face.h"
#include "../entity/loop.h"
#include "../entity/vertex.h"
#include "../entity/halfedge.h"
#include "../entity/ipoint.h"


MVR::MVR( HEDModel& _model, Face* _f, int _v, double _x, double _y, double _z )
: m_face( _f )
, m_v( _v )
, m_x( _x )
, m_y( _y )
, m_z( _z )
, m_model( &_model )
{

}


void
MVR::execute()
{
  std::cout << "\nMVR::execute() \n";

  if( m_face == NULL )
  {
    m_face = m_model->getFace(m_x,m_y,m_z,1e-5);

  }

  Solid* solid = m_face->getSolid();

  Loop* newloop = new Loop(m_face);
  IPoint* point = new IPoint(m_x, m_y, m_z);
  Vertex* newvertex = new Vertex(point,solid);
  HalfEdge* newhe = new HalfEdge();

  newloop->setLedg( newhe );
  newhe->setWloop(newloop);
  newhe->setNxt(newhe);
  newhe->setPrv(newhe);
  newhe->setVtx(newvertex);
  newhe->setEdg(NULL);
  newvertex->setVertexno(m_v);
  newvertex->setVedge(newhe);

}


void
MVR::unExecute()
{
  std::cout << "\nMVR::unExecute() NOT IMPLEMENTED!\n";

  Vertex* vtx = m_model->getVertex(m_x,m_y,m_z,1e-5);

  KVR kvr( vtx->getVEdge()->getLoop() );
  kvr.execute();

  m_face = NULL;

}







